package com.ladybug.flow.modules.system.controller;

import com.ladybug.flow.common.annotation.LoginUser;
import com.ladybug.flow.common.security.dto.LoginUserDTO;
import com.ladybug.flow.common.vo.ResponseResult;
import com.ladybug.flow.modules.system.domain.entitys.SysResources;
import com.ladybug.flow.modules.system.service.SysResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xianglongfei
 * @description
 * @createDate 2023/1/11 13:39
 */

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private SysResourcesService sysResourcesService;

    @GetMapping("/list")
    public ResponseResult<List<SysResources>> menuList(@LoginUser LoginUserDTO user){
        List<SysResources> sysResourcesList = sysResourcesService.getMenuList(null);
        return ResponseResult.success(sysResourcesList);
    }
    @GetMapping("/list/{pid}")
    public ResponseResult<List<SysResources>> getMenuListByPid(@PathVariable String pid){
        List<SysResources> sysResourcesList = sysResourcesService.getMenuList(pid);
        return ResponseResult.success(sysResourcesList);
    }
    @GetMapping("/{id}")
    public ResponseResult<SysResources> getmenuInfo(@PathVariable String id){
        return ResponseResult.success(sysResourcesService.getById(id));
    }

    @GetMapping("/listTree")
    public ResponseResult<List<SysResources>> listTree(){
        return ResponseResult.success(sysResourcesService.listTree());
    }

    @PostMapping("/editResource")
    public ResponseResult editResource(@RequestBody SysResources sysResources){
        //sysResourcesService.updateById(sysResources);
        sysResourcesService.updateResource(sysResources);
        return ResponseResult.success();
    }

    @PostMapping("/addResource")
    public ResponseResult addResource(@RequestBody SysResources sysResources){
        sysResourcesService.addResource(sysResources);
        return ResponseResult.success();
    }

}
